<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>影多多</title>
    <link rel="stylesheet" type="text/css" href="/public/static/aui/css/aui.css" />
    <link rel="stylesheet" type="text/css" href="/public/static/aui/css/style.css" />
    <script type="text/javascript" src="/public/static/aui/script/api.js"></script>
    <script type="text/javascript" src="/public/static/assets/js/jquery-1.11.1.min.js"></script>
    <style type="text/css">
    body{
      background: #fff;
    }
    .myui-from{
      padding: 1em;
    }
    .myui-from-code-input{
      border: 0.5em solid #eee;
    }
    input::-webkit-input-placeholder {
      color: #fff;
    }
    .disabled{
      background: #cecece;
    }
    </style>
</head>
<body class="login-bg2">
  <header class="aui-bar aui-bar-nav" id="aui-header">
      <div id="title" class="aui-title">注册</div>
  </header>


  <div class="myui-from">
    <ul class="myui-from-list">
      <li class="myui-from-list-item">
        <div class="myui-code">
          <input id="phone" type="tel"  minlength="11" maxlength="11" placeholder="输入手机号码" class="myui-from-code-input">
          <button id="btn1" type="button" name="button" style="width:20%;float:left;height: 2.2rem;" class="myui-from-code-button" onclick="getCode()">获取</button>
        </div>
      </li>
      <li class="myui-from-list-item">
        <input id="yzcode" type="tel" minlength="6" maxlength="6" placeholder="短信验证码" class="myui-from-list-item-input">
      </li>
      <li class="myui-from-list-item">
        <input id="username" type="text" placeholder="账号" class="myui-from-list-item-input">
      </li>
      <li class="myui-from-list-item">
        <input id="password" type="password" placeholder="设置密码" class="myui-from-list-item-input">
      </li>
       <li class="myui-from-list-item">
        <input id="share_ma" type="text" minlength="6" maxlength="6" placeholder="邀请码(必填)" class="myui-from-list-item-input" value="{$share_ma}">
      </li>
      <li class="myui-from-list-item">
        <div id="btn2" type="button" name="button" class="aui-btn aui-btn-primary aui-btn-block" onclick="toReg()">立即注册</div>
      </li>
      <li class="myui-from-list-item">
        <br>
        <div id="btn2" type="button" name="button" class="aui-btn aui-btn-default aui-btn-block" onclick="toDownload()">已注册</div>
      </li>
    </ul>
  </div>
</body>
<script type="text/javascript">
    //去注册
    var code_data = '';
    var btn_enable = true;
    function toReg(){
      var phone = $('#phone').val();
      var username = $('#username').val();
      var password = $('#password').val();
      var yzcode = $('#yzcode').val();
      var share_ma = $('#share_ma').val();
      if(username == ''){
        alert('请输入登录账号');
        return;
      }
      if(password == ''){
        alert('请输入密码');
        return;
      }

      if(password.length < 6){
        alert('请输入6位以上密码');
        return;
      }
      if(yzcode != code_data){
        alert(yzcode+code_data+'您输入的验证码不正确');
        return;
      }
      user = $('#username').val();
      pass = $('#password').val();
      
      if(!btn_enable) {
        return false;
      }
      $('#btn2').addClass('disabled');
      btn_enable = false;
      $.ajax({
        url: '/login/login/create.html',
        data: {
                phone:phone,
                username: username,
                password:password,
                share_ma:share_ma
            },
        dataType:'json',
        success: function(res) {
          if(res.code==1){
            window.location.href="http://download.99kk419.cn/login/apppage/download?reg=success";
          } else {
            alert(res.msg);
            $('#btn2').removeClass('disabled');
            btn_enable = true;
          }
        }
      });
    }

    // 已注册直接下载
    function toDownload(){
      window.location.href="http://download.99kk419.cn/login/apppage/download?reg=success";
    }

    //获取验证码
    function getCode(){
      var yzcode = $api.val($api.byId('yzcode'));
      var btn1 = $api.byId('btn1');
      var username = $api.val($api.byId('phone'));
      localStorage.setItem('reg_name',username);
      
      if(username == ''){
        alert('请输入手机号码');
        return;
      }
      if(username.length != 11){
        alert('请输入11位手机号码');
        return;
      }
      code_data = RndNum(6);
      var content = escape('#code#='+code_data);
      console.log(code_data);
      var url = 'http://v.juhe.cn/sms/send?mobile='+username+'&tpl_id=127153&tpl_value='+content+'&key=5c16751a03176d199b1056e65f583f53';
      $.ajax({
          url: '/login/apppage/sendsms',
          data: {'url':url},
          method: 'get',
          success: function(res){

            var nuw = 60;
            var timer = setInterval(function(){
              nuw --;

              if (nuw < 1) {
                btn1.innerHTML = '获取';
                clearInterval(timer);
                onoff = true;
              }else {
                btn1.innerHTML = nuw+'s';
              }


            },1000)
      }});


    }

    //生成验证码
    function RndNum(n){
      var rnd="";
      for(var i=0;i<n;i++)
          rnd+=Math.floor(Math.random()*10);
      return rnd;
    }


    function closeWin(){
        api.closeWin({
        });
    }

    function openWin(name){
          var delay = 0;
          if(api.systemType != 'ios'){
              delay = 300;
          }
          api.openWin({
              name: ''+name+'',
              url: ''+name+'.html',
              bounces:false,
              delay: delay,
              slidBackEnabled:true,
              vScrollBarEnabled:false
          });
      }
</script>
</html>
